package com.im.main;

import com.im.common.toolkit.http.HttpClientUtils;

import java.util.HashMap;
import java.util.List;

/**
 * @author gongym
 * @date 2019/1/21 14:35
 */
public class DownloadWithRange implements Runnable {

  private List<String> urlList;
  private String baseSavePath;
  private int start;
  private int end;

  DownloadWithRange(List<String> urlList, String baseSavePath, int start, int end) {
    this.urlList = urlList;
    this.baseSavePath = baseSavePath;
    this.start = start;
    this.end = end;
  }

  @Override
  public void run() {
    HashMap<String, String> header = new HashMap<>(16);
    header.put(
        "User-Agent",
        "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.79 Safari/537.1");
    for (int i = start; i < end; i++) {
      HttpClientUtils.downloadImage(urlList.get(i), header, null, baseSavePath + i + ".jpg");
      System.out.println("第：" + i + "张图片下载完毕{" + urlList.get(i) + "}");
    }
  }
}
